
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>04 DQL · 书名</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="作者">
        <meta name="identifier" content="图书编号" scheme="ISBN">
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-code/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-back-to-top-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-intopic-toc/style.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-flexible-alerts/style.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-theme-comscore/test.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="05 DCL.html" />
    
    
    <link rel="prev" href="03 DML.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    书名
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">Books</li>
        
        
    
        <li class="chapter " data-level="2.1" >
            
                <span>
            
                    
                    Java
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1.1" data-path="../java/001环境变量.html">
            
                <a href="../java/001环境变量.html">
            
                    
                    001环境变量
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.2" data-path="../java/002Java初体验.html">
            
                <a href="../java/002Java初体验.html">
            
                    
                    002Java初体验
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.3" data-path="../java/003变量命名及数据类型.html">
            
                <a href="../java/003变量命名及数据类型.html">
            
                    
                    003变量命名及数据类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.4" data-path="../java/004运算符.html">
            
                <a href="../java/004运算符.html">
            
                    
                    004运算符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.5" data-path="../java/005选择结构.html">
            
                <a href="../java/005选择结构.html">
            
                    
                    005选择结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.6" data-path="../java/006循环结构.html">
            
                <a href="../java/006循环结构.html">
            
                    
                    006循环结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.7" data-path="../java/007数组.html">
            
                <a href="../java/007数组.html">
            
                    
                    007数组
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.8" data-path="../java/008类和对象方法.html">
            
                <a href="../java/008类和对象方法.html">
            
                    
                    008类和对象方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.9" data-path="../java/009构造方法.html">
            
                <a href="../java/009构造方法.html">
            
                    
                    009构造方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.10" data-path="../java/010封装与关键字static.html">
            
                <a href="../java/010封装与关键字static.html">
            
                    
                    010封装与关键字Static
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.11" data-path="../java/011 继承.html">
            
                <a href="../java/011 继承.html">
            
                    
                    011 继承
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.12" data-path="../java/012方法重写.html">
            
                <a href="../java/012方法重写.html">
            
                    
                    012方法重写
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.13" data-path="../java/013多态.html">
            
                <a href="../java/013多态.html">
            
                    
                    013多态
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.14" data-path="../java/014抽象类抽象方法.html">
            
                <a href="../java/014抽象类抽象方法.html">
            
                    
                    014抽象类抽象方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.15" data-path="../java/015接口.html">
            
                <a href="../java/015接口.html">
            
                    
                    015接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.16" data-path="../java/016异常.html">
            
                <a href="../java/016异常.html">
            
                    
                    016异常
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.17" data-path="../java/017集合.html">
            
                <a href="../java/017集合.html">
            
                    
                    017集合
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.18" data-path="../java/017集合2.html">
            
                <a href="../java/017集合2.html">
            
                    
                    017集合2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.19" data-path="../java/018泛型.html">
            
                <a href="../java/018泛型.html">
            
                    
                    018泛型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.20" data-path="../java/019Collections算法类.html">
            
                <a href="../java/019Collections算法类.html">
            
                    
                    019Collections算法类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.21" data-path="../java/020枚举.html">
            
                <a href="../java/020枚举.html">
            
                    
                    020枚举
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.22" data-path="../java/021包装类.html">
            
                <a href="../java/021包装类.html">
            
                    
                    021包装类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.23" data-path="../java/022常用类.html">
            
                <a href="../java/022常用类.html">
            
                    
                    022常用类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.24" data-path="../java/023File类.html">
            
                <a href="../java/023File类.html">
            
                    
                    023File类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.25" data-path="../java/024IO流.html">
            
                <a href="../java/024IO流.html">
            
                    
                    024IO流
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.26" data-path="../java/025多线程.html">
            
                <a href="../java/025多线程.html">
            
                    
                    025多线程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.27" data-path="../java/025多线程线程池.html">
            
                <a href="../java/025多线程线程池.html">
            
                    
                    025多线程线程池
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.28" data-path="../java/026网络编程Socket.html">
            
                <a href="../java/026网络编程Socket.html">
            
                    
                    026网络编程Socket
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.29" data-path="../java/027XML解析.html">
            
                <a href="../java/027XML解析.html">
            
                    
                    027XML解析
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.30" data-path="../java/028 注解.html">
            
                <a href="../java/028 注解.html">
            
                    
                    028 注解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.31" data-path="../java/029 Lambda表达式.html">
            
                <a href="../java/029 Lambda表达式.html">
            
                    
                    029 Lambda表达式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.32" data-path="../java/029 反射.html">
            
                <a href="../java/029 反射.html">
            
                    
                    029 反射
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.2" >
            
                <span>
            
                    
                    Mybatis
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.2.1" data-path="../mybatis/MyBatis.html">
            
                <a href="../mybatis/MyBatis.html">
            
                    
                    MyBatis
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.2.1.1" >
            
                <span>
            
                    
                    MyBatis
            
                </span>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.3" >
            
                <span>
            
                    
                    Mysql
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.3.1" data-path="01 SQL通用语法.html">
            
                <a href="01 SQL通用语法.html">
            
                    
                    01 SQL通用语法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.2" data-path="02 DDL.html">
            
                <a href="02 DDL.html">
            
                    
                    02 DDL
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.3" data-path="03 DML.html">
            
                <a href="03 DML.html">
            
                    
                    03 DML
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="2.3.4" data-path="04 DQL.html">
            
                <a href="04 DQL.html">
            
                    
                    04 DQL
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.5" data-path="05 DCL.html">
            
                <a href="05 DCL.html">
            
                    
                    05 DCL
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.6" data-path="06 函数.html">
            
                <a href="06 函数.html">
            
                    
                    06 函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.7" data-path="07 约束.html">
            
                <a href="07 约束.html">
            
                    
                    07 约束
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.8" data-path="08 多表查询.html">
            
                <a href="08 多表查询.html">
            
                    
                    08 多表查询
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.9" data-path="09 事务.html">
            
                <a href="09 事务.html">
            
                    
                    09 事务
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.10" data-path="999zzz.html">
            
                <a href="999zzz.html">
            
                    
                    999zzz
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.11" data-path="MySql.html">
            
                <a href="MySql.html">
            
                    
                    MySql
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.12" data-path="sql.html">
            
                <a href="sql.html">
            
                    
                    Sql
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.4" >
            
                <span>
            
                    
                    Spring
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.4.1" data-path="../spring/spring.html">
            
                <a href="../spring/spring.html">
            
                    
                    Spring
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.5" >
            
                <span>
            
                    
                    SpringMVC
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.5.1" data-path="../springMVC/springMVC.html">
            
                <a href="../springMVC/springMVC.html">
            
                    
                    SpringMVC
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.6" >
            
                <span>
            
                    
                    整合
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.6.1" data-path="../整合/Mybatis框架.html">
            
                <a href="../整合/Mybatis框架.html">
            
                    
                    Mybatis框架
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.2" data-path="../整合/SpringBoot.html">
            
                <a href="../整合/SpringBoot.html">
            
                    
                    SpringBoot
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.3" data-path="../整合/springmvc框架.html">
            
                <a href="../整合/springmvc框架.html">
            
                    
                    Springmvc框架
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.4" data-path="../整合/spring框架.html">
            
                <a href="../整合/spring框架.html">
            
                    
                    Spring框架
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >04 DQL</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="dql&#x4ECB;&#x7ECD;">DQL&#x4ECB;&#x7ECD;</h1>
<p>DQL&#x5168;&#x79F0;Data Query Language(&#x6570;&#x636E;&#x67E5;&#x8BE2;&#x8BED;&#x53E5;), &#x6570;&#x636E;&#x67E5;&#x8BE2;&#x8BED;&#x8A00;, &#x7528;&#x6765;&#x67E5;&#x8BE2;&#x6570;&#x636E;&#x5E93;&#x4E2D;&#x90E8;&#x8868;&#x7684;&#x8BB0;&#x5F55;</p>
<p>&#x67E5;&#x8BE2;&#x5173;&#x952E;&#x5B57;: select</p>
<h1 id="dql&#x8BED;&#x6CD5;&#x7ED3;&#x6784;">DQL&#x8BED;&#x6CD5;&#x7ED3;&#x6784;</h1>
<pre><code class="lang-mysql">select
    &#x5B57;&#x6BB5;&#x5217;&#x8868;
from
    &#x8868;&#x540D;&#x5217;&#x8868;
where
    &#x6761;&#x4EF6;&#x5217;&#x8868;
group by
    &#x5206;&#x7EC4;&#x5B57;&#x6BB5;&#x5217;&#x8868;
having
    &#x5206;&#x7EC4;&#x540E;&#x6761;&#x4EF6;&#x5217;&#x8868;
order by
    &#x6392;&#x5E8F;&#x897F;&#x7AEF;&#x5217;&#x8868;
limit
    &#x5206;&#x9875;&#x53C2;&#x6570;
</code></pre>
<h1 id="dql-&#x57FA;&#x672C;&#x67E5;&#x8BE2;">DQL-&#x57FA;&#x672C;&#x67E5;&#x8BE2;</h1>
<ol>
<li><p>&#x67E5;&#x8BE2;&#x591A;&#x4E2A;&#x5B57;&#x6BB5;</p>
<pre><code class="lang-mysql">select &#x5B57;&#x6BB5;1,&#x5B57;&#x6BB5;2,&#x5B57;&#x6BB5;3... from &#x8868;&#x540D;;
select * from &#x8868;&#x540D;;
</code></pre>
</li>
</ol>
<ol>
<li><p>&#x8BBE;&#x7F6E;&#x522B;&#x540D;</p>
<pre><code class="lang-mysql">select &#x5B57;&#x6BB5;1[as &#x522B;&#x540D;2],&#x5B57;&#x6BB5;2[as &#x522B;&#x540D;2],... from &#x8868;&#x540D;;
</code></pre>
</li>
</ol>
<ol>
<li><p>&#x53BB;&#x9664;&#x91CD;&#x590D;&#x8BB0;&#x5F55;</p>
<pre><code class="lang-mysql">select distinct &#x5B57;&#x6BB5;&#x5217;&#x8868; from &#x8868;&#x540D;;
</code></pre>
</li>
</ol>
<h1 id="dql-&#x6761;&#x4EF6;&#x67E5;&#x8BE2;">DQL-&#x6761;&#x4EF6;&#x67E5;&#x8BE2;</h1>
<ol>
<li><p>&#x8BED;&#x6CD5;</p>
<pre><code class="lang-mysql">select &#x5B57;&#x6BB5;&#x5217;&#x8868; from &#x8868;&#x540D; where &#x6761;&#x4EF6;&#x5217;&#x8868;;
</code></pre>
</li>
</ol>
<ol>
<li>&#x6761;&#x4EF6;</li>
</ol>
<table>
<thead>
<tr>
<th style="text-align:left">&#x6BD4;&#x8F83;&#x8FD0;&#x7B97;&#x7B26;</th>
<th style="text-align:left">&#x529F;&#x80FD;</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">&gt;</td>
<td style="text-align:left">&#x5927;&#x4E8E;</td>
</tr>
<tr>
<td style="text-align:left">&gt;=</td>
<td style="text-align:left">&#x5927;&#x4E8E;&#x7B49;&#x4E8E;</td>
</tr>
<tr>
<td style="text-align:left">&lt;</td>
<td style="text-align:left">&#x5C0F;&#x4E8E;</td>
</tr>
<tr>
<td style="text-align:left">&lt;=</td>
<td style="text-align:left">&#x5C0F;&#x4E8E;&#x7B49;&#x4E8E;</td>
</tr>
<tr>
<td style="text-align:left">=</td>
<td style="text-align:left">&#x7B49;&#x4E8E;</td>
</tr>
<tr>
<td style="text-align:left">&lt;&gt; !=</td>
<td style="text-align:left">&#x4E0D;&#x7B49;&#x4E8E;</td>
</tr>
<tr>
<td style="text-align:left">between ... and...</td>
<td style="text-align:left">&#x5728;&#x67D0;&#x4E2A;&#x8303;&#x56F4;&#x4E4B;&#x95F4;</td>
</tr>
<tr>
<td style="text-align:left">in(...)</td>
<td style="text-align:left">&#x5728;in&#x4E4B;&#x540E;&#x7684;&#x5217;&#x8868;&#x4E2D;&#x7684;&#x503C;,&#x591A;&#x9009;&#x4E00;</td>
</tr>
<tr>
<td style="text-align:left">like &#x5360;&#x4F4D;&#x7B26;</td>
<td style="text-align:left">&#x6A21;&#x7CCA;&#x5339;&#x914D;( <code>_</code> &#x5339;&#x914D;&#x5355;&#x4E2A;&#x5B57;&#x7B26;, <code>%</code>&#x5339;&#x914D;&#x4EFB;&#x610F;&#x591A;&#x4E2A;&#x5B57;&#x7B26; )</td>
</tr>
<tr>
<td style="text-align:left">is null</td>
<td style="text-align:left">&#x662F; null</td>
</tr>
</tbody>
</table>
<table>
<thead>
<tr>
<th>&#x903B;&#x8F91;&#x8FD0;&#x7B97;&#x7B26;</th>
<th>&#x529F;&#x80FD;</th>
</tr>
</thead>
<tbody>
<tr>
<td>and &#x6216; &amp;&amp;</td>
<td>&#x5E76;&#x4E14;(&#x591A;&#x4E2A;&#x6761;&#x4EF6;&#x540C;&#x65F6;&#x6210;&#x7ACB;)</td>
</tr>
<tr>
<td>or &#x6216;&#x8005; \</td>
<td>\</td>
<td></td>
<td>&#x6216;&#x8005;(&#x591A;&#x4E2A;&#x6761;&#x4EF6;&#x4EFB;&#x610F;&#x4E00;&#x4E2A;&#x6210;&#x7ACB;)</td>
</tr>
<tr>
<td>not &#x6216; !</td>
<td>&#x975E;, &#x4E0D;&#x662F;</td>
</tr>
</tbody>
</table>
<h1 id="dql-&#x51FD;&#x6570;">DQL-&#x51FD;&#x6570;</h1>
<ol>
<li><p>&#x4ECB;&#x7ECD;</p>
<p>&#x5C06;&#x4E00;&#x5217;&#x6570;&#x636E;&#x4F5C;&#x4E3A;&#x4E00;&#x4E2A;&#x6574;&#x4F53;, &#x8FDB;&#x884C;&#x7EB5;&#x5411;&#x8BA1;&#x7B97;</p>
</li>
<li><p>&#x5E38;&#x89C1;&#x805A;&#x5408;&#x51FD;&#x6570;</p>
</li>
</ol>
<table>
<thead>
<tr>
<th>&#x51FD;&#x6570;</th>
<th>&#x529F;&#x80FD;</th>
</tr>
</thead>
<tbody>
<tr>
<td>count</td>
<td>&#x7EDF;&#x8BA1;&#x6570;&#x91CF;</td>
</tr>
<tr>
<td>max</td>
<td>&#x6700;&#x5927;&#x503C;</td>
</tr>
<tr>
<td>min</td>
<td>&#x6700;&#x5C0F;&#x662F;</td>
</tr>
<tr>
<td>avg</td>
<td>&#x5E73;&#x5747;&#x503C;</td>
</tr>
<tr>
<td>sum</td>
<td>&#x6C42;&#x548C;</td>
</tr>
</tbody>
</table>
<ol>
<li>&#x8BED;&#x6CD5;</li>
</ol>
<pre><code class="lang-mysql">select &#x805A;&#x5408;&#x51FD;&#x6570;(&#x5B57;&#x6BB5;&#x5217;&#x8868;) from &#x8868;&#x540D;;

select count(*) from stu;
select count(idcard) from stu;

select avg(age) from stu;
</code></pre>
<h1 id="dql-&#x5206;&#x7EC4;&#x67E5;&#x8BE2;">DQL-&#x5206;&#x7EC4;&#x67E5;&#x8BE2;</h1>
<ol>
<li>&#x8BED;&#x6CD5;</li>
</ol>
<pre><code class="lang-mysql">select &#x5B57;&#x6BB5;&#x5217;&#x8868; from &#x8868;&#x540D; [where &#x6761;&#x4EF6;] group by &#x5206;&#x7EC4;&#x5B57;&#x5178;&#x540D; [having &#x5206;&#x7EC4;&#x8FC7;&#x6EE4;&#x6761;&#x4EF6;];
</code></pre>
<ol>
<li>where &#x548C; having &#x533A;&#x522B;<ol>
<li>&#x6267;&#x884C;&#x65F6;&#x673A;&#x4E0D;&#x540C;: where&#x662F;&#x5206;&#x7EC4;&#x4E4B;&#x524D;&#x8FDB;&#x884C;&#x8FC7;&#x6EE4;, &#x4E0D;&#x6EE1;&#x8DB3;where&#x6761;&#x4EF6;&#x4E0D;&#x53C2;&#x4E0E;&#x5206;&#x7EC4;; &#x800C; having &#x662F;&#x5206;&#x7EC4;&#x4E4B;&#x540E;&#x5BF9;&#x7ED3;&#x679C;&#x8FDB;&#x884C;&#x8FC7;&#x6EE4;</li>
<li>&#x5224;&#x65AD;&#x6761;&#x4EF6;&#x4E0D;&#x540C;: where&#x4E0D;&#x80FD;&#x5BF9;&#x805A;&#x5408;&#x51FD;&#x6570;&#x8FDB;&#x884C;&#x5224;&#x65AD;, &#x800C; having &#x53EF;&#x4EE5;</li>
</ol>
</li>
</ol>
<p><strong>&#x6CE8;&#x610F;:</strong></p>
<ul>
<li>&#x6267;&#x884C;&#x987A;&#x5E8F;: where&gt;&#x805A;&#x5408;&#x51FD;&#x6570;&gt;having</li>
<li>&#x5206;&#x7EC4;&#x4E4B;&#x540E;, &#x67E5;&#x8BE2;&#x7684;&#x5B57;&#x6BB5;&#x4E00;&#x822C;&#x4E3A;&#x805A;&#x5408;&#x51FD;&#x6570;&#x548C;&#x5206;&#x7EC4;&#x5B57;&#x6BB5;, &#x67E5;&#x8BE2;&#x5176;&#x4ED6;&#x5B57;&#x6BB5;&#x65E0;&#x4EFB;&#x4F55;&#x610F;&#x4E49;</li>
</ul>
<h1 id="dql-&#x6392;&#x5E8F;&#x67E5;&#x8BE2;">DQL-&#x6392;&#x5E8F;&#x67E5;&#x8BE2;</h1>
<ol>
<li>&#x8BED;&#x6CD5;</li>
</ol>
<pre><code class="lang-mysql">select &#x5B57;&#x6BB5;&#x5217;&#x8868; from &#x8868;&#x540D; order by &#x5B57;&#x6BB5;1 &#x6392;&#x5217;&#x65B9;&#x5F0F;1, &#x5B57;&#x6BB5;3 &#x6392;&#x5217;&#x65B9;&#x5F0F;2;
</code></pre>
<ol>
<li>&#x6392;&#x5E8F;&#x65B9;&#x5F0F;<ol>
<li>asc: &#x5347;&#x5E8F;( &#x9ED8;&#x8BA4;&#x503C; )</li>
<li>desc: &#x964D;&#x5E8F;</li>
</ol>
</li>
</ol>
<p><strong>&#x6CE8;&#x610F;:</strong> &#x5982;&#x679C;&#x662F;&#x591A;&#x4E2A;&#x5B57;&#x6BB5;&#x6392;&#x5E8F;,&#x5F53;&#x7B2C;&#x4E00;&#x4E2A;&#x76F8;&#x540C;&#x65F6;,&#x624D;&#x4F1A;&#x6839;&#x636E;&#x7B2C;&#x4E8C;&#x4E2A;&#x5B57;&#x6BB5;&#x8FDB;&#x884C;&#x6392;&#x5E8F;</p>
<h1 id="dql-&#x5206;&#x9875;&#x67E5;&#x8BE2;">DQL-&#x5206;&#x9875;&#x67E5;&#x8BE2;</h1>
<ol>
<li>&#x8BED;&#x6CD5;</li>
</ol>
<pre><code class="lang-mysql">select &#x5B57;&#x6BB5;&#x5217;&#x8868; from &#x8868;&#x540D; limit &#x8D77;&#x59CB;&#x7D22;&#x5F15;,&#x67E5;&#x8BE2;&#x8BB0;&#x5F55;&#x6570;;
</code></pre>
<p><strong>&#x6CE8;&#x610F;:</strong> </p>
<ul>
<li>&#x8D77;&#x59CB;&#x7D22;&#x5F15;&#x4ECE; 0 &#x5F00;&#x59CB;, &#x8D77;&#x59CB;&#x7D22;&#x5F15; = ( &#x67E5;&#x8BE2;&#x9875;&#x7801;-1 )*&#x6BCF;&#x9875;&#x663E;&#x793A;&#x8BB0;&#x5F55;&#x6570;</li>
<li>&#x5206;&#x9875;&#x67E5;&#x8BE2;&#x662F;&#x6570;&#x636E;&#x5E93;&#x7684;&#x65B9;&#x8A00;,&#x4E0D;&#x540C;&#x7684;&#x6570;&#x636E;&#x5E93;&#x6709;&#x4E0D;&#x540C;&#x7684;&#x5B9E;&#x73B0;, mysql&#x4E2D;&#x7684;&#x662F; limit</li>
<li>&#x5982;&#x679C;&#x67E5;&#x8BE2;&#x7684;&#x662F;&#x7B2C;&#x4E00;&#x9875;&#x7684;&#x6570;&#x636E;,&#x8D77;&#x59CB;&#x7D22;&#x5F15;&#x53EF;&#x4EE5;&#x7701;&#x7565;,&#x76F4;&#x63A5;&#x7B80;&#x5199; limit 10</li>
</ul>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="03 DML.html" class="navigation navigation-prev " aria-label="Previous page: 03 DML">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="05 DCL.html" class="navigation navigation-next " aria-label="Next page: 05 DCL">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"04 DQL","level":"2.3.4","depth":2,"next":{"title":"05 DCL","level":"2.3.5","depth":2,"path":"books/mysql/05 DCL.md","ref":"books/mysql/05 DCL.md","articles":[]},"previous":{"title":"03 DML","level":"2.3.3","depth":2,"path":"books/mysql/03 DML.md","ref":"books/mysql/03 DML.md","articles":[]},"dir":"ltr"},"config":{"plugins":["search-pro","code","back-to-top-button","theme-comscore","intopic-toc","flexible-alerts","expandable-chapters"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"intopic-toc":{"selector":".markdown-section h1, .markdown-section h2, .markdown-section h3, .markdown-section h4, .markdown-section h5, .markdown-section h6","mode":"nested","maxDepth":6,"isCollapsed":true,"isScrollspyActive":true,"visible":true,"label":"In this article"},"search-pro":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"code":{"copyButtons":true},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"theme-comscore":{},"back-to-top-button":{},"flexible-alerts":{"style":"callout","note":{"label":"Note","icon":"fa fa-info-circle","className":"info"},"tip":{"label":"Tip","icon":"fa fa-lightbulb-o","className":"tip"},"warning":{"label":"Warning","icon":"fa fa-exclamation-triangle","className":"warning"},"danger":{"label":"Attention","icon":"fa fa-ban","className":"danger"}},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"expandable-chapters":{}},"theme":"default","author":"作者","lang":"zh-cn","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"isbn":"图书编号","variables":{},"title":"书名","gitbook":"*","description":"描述"},"file":{"path":"books/mysql/04 DQL.md","mtime":"2022-08-31T11:37:42.217Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2023-03-01T12:24:55.135Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-code/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-back-to-top-button/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-intopic-toc/anchor.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-intopic-toc/gumshoe.polyfills.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-intopic-toc/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-flexible-alerts/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-theme-comscore/test.js"></script>
        
    

    </body>
</html>

